package com.imooc.ecommerce.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.ecommerce.common.TableId;
import com.imooc.ecommerce.order.OrderInfo;
import com.imooc.ecommerce.service.IOrderService;
import com.imooc.ecommerce.vo.SingleOrderItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单服务对外 Http 接口
 *
 * @author zhangshao
 * @since 2023/12/14 22:47
 */
@Api(tags = "订单服务")
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @ApiOperation(value = "创建", notes = "购买(分布式事务): 创建订单 --> 扣减库存 --> 扣减余额 --> 发送物流消息 ", httpMethod = "POST")
    @PostMapping("/create-order")
    public TableId createOrder(@RequestBody OrderInfo orderInfo) {
        return orderService.createOrder(orderInfo);
    }

    @ApiOperation(value = "订单信息", notes = "获取当前用户的订单信息: 带有分页", httpMethod = "GET")
    @GetMapping("/order-detail")
    public IPage<SingleOrderItem> getSimpleOrderDetailByPage(@RequestParam(required = false, defaultValue = "1") int page) {
        return orderService.getSimpleOrderDetailByPage(page);
    }

}
